<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    <div class="layui-form layuimini-form">
        <div class="layui-form-item" id="pnameBox">
            <label class="layui-form-label required">工地名称</label>
            <div class="layui-input-block">
                <input type="text" name="pname" id="pname" lay-verify="" lay-reqtext="工地名称不能为空" placeholder="请输入工地名称"
                    value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">详细地址</label>
            <div class="layui-input-block">
                <input type="text" name="siteDetail" id="siteDetail" lay-verify="required" lay-reqtext="详细地址不能为空"
                    placeholder="请输入详细地址" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">收货人姓名</label>
            <div class="layui-input-block">
                <input type="text" name="workername" id="workername" lay-verify="required" lay-reqtext="收货人姓名不能为空"
                    placeholder="请输入收货人姓名" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">收货人电话</label>
            <div class="layui-input-block">
                <input type="text" name="workerphone" id="workerphone" lay-verify="required|phone"
                    lay-reqtext="收货人电话不能为空" placeholder="请输入收收货人电话" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
    <script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer,
                $ = layui.$;
            var url = window.location.href;
            var flag = url.split('=')[1];
            $('body').ready(function () {
                if (flag == '1') {
                    $('#pnameBox').css('display', 'none');
                }

            })
            //监听提交
            form.on('submit(saveBtn)', function (data) {
                var remember = 0; //是否记住密码
                var password = '';
                var username = '';
                var strCookie = document.cookie;
                if (strCookie != '') {
                    var arrCookie = strCookie.split("; ");
                    for (i = 0; i < arrCookie.length; i++) {
                        var arr = arrCookie[i].split("=");
                        if (arr[0] == 'username')
                            username = arr[1];
                        else if (arr[0] == 'remember')
                            remember = 1;
                        else if (arr[0] == 'password')
                            password = arr[1];
                    }
                }

                data4 = data.field;
                var index = layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                }, function () {
                    data4.flag = flag;
                    data4.mode = '7';
                    data4.username = username;
                    $.get('/workplace', data4, function (re) {
                        if (re == '1') {
                            layer.close(index);
                            var iframeIndex = parent.layer.getFrameIndex(
                                window.name);
                            parent.layer.close(iframeIndex);
                        }
                    })
                });

                return false;
            });

        });
    </script>
</body>

</html>